package handler

import (
	"bbs-web/internal/service"
	"bbs-web/internal/web/resp"
	"bbs-web/pkg/ginplus"
	"github.com/gin-gonic/gin"
)

type CaptchaHandler struct {
	svc service.IcaptchaService
}

func NewCaptchaHandler(svc service.IcaptchaService) *CaptchaHandler {
	return &CaptchaHandler{svc: svc}
}

func (c *CaptchaHandler) ImageCaptcha(ctx *gin.Context) (ginplus.Result, error) {
	id, path, err := c.svc.MakeCaptcha()
	if err != nil {
		return ginplus.Result{
			Msg: "系统错误",
		}, nil
	}
	return ginplus.Result{
		Data: resp.CaptchaResponse{
			CaptchaId: id,
			PicPath:   path,
		},
	}, nil
}
